<template>
  <div class="container">
    <div class="title">{{title}}</div>
    <div class="tag-group">
      <van-tag
        v-if="show1"
        closeable
        size="medium"
        type="primary"
        @close="close"
      >
      {{value1}}
      </van-tag>
      <van-tag
        v-if="show2"
        closeable
        size="medium"
        type="primary"
        @close="close"
      >
      {{value2}}
      </van-tag>
    </div>
    <div class="picker-placeholder">请选择</div>
    <van-field
      readonly
      clickable
      @click="showPicker = true"
    />
    <van-popup v-model="showPicker" round position="bottom">
      <van-picker
        show-toolbar
        :columns="columns"
        @cancel="showPicker = false"
        @confirm="onConfirm"
      />
    </van-popup>
  </div>
</template>
<script>
export default {
  props: {
    title: {
      type: String,
      default: '标题',
    },
    defaultValue: {
      type: Object,
      default: ()=> ({
        value1: '空',
        value2: '空',
      }),
    },
    defaultColumns: {
      type: Array,
      default:()=> [],
    },
  },
  data() {
    return {
      show1: true,
      show2: true,
      value1: this.defaultValue.value1,
      value2: this.defaultValue.value2,
      showPicker: false,
      columns: this.defaultColumns,
    }
  },
  methods: {
    onConfirm(valueArray,keyArray) {
      debugger
      this.value1 = valueArray[0]
      this.value2 = valueArray[1]
      this.showPicker = false
      const keyId1 = this.defaultColumns[keyArray[0]].id
      const keyId2 = this.defaultColumns[keyArray[0]].children[keyArray[1]].id
      this.$emit('saveValue', { id1: keyId1, id2: keyId2 })
    },
    close() {
      this.show = false
    },
  },
}
</script>
<style lang="scss" scoped>
.container {
  position: relative;
  width: 375px;
  height: 106px;
  margin-bottom: 10px;
  overflow: hidden;
  background: #ffffff;
  .title {
    position: absolute;
    top: 10px;
    left: 36px;
    position: absolute;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #8c97b2;
  }
  .picker-placeholder {
    position: absolute;
    left: 36px;
    bottom: 14px;
    position: absolute;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #8C97B2;
  }
  .van-field {
    position: absolute;
    bottom: 0px;
    left: 0px;
    background: transparent;
  }
  .tag-group {
    display: flex;
    position: absolute;
    top: 36px;
    left: 20px;
    .van-tag {
      background: #EEEFF3;
      border-radius: 5px;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #002170;
      padding: 8px 14px;
      margin-right: 10px;
    }
  }
  .van-icon-cross {
    &::before {
      content: '\F034';
      margin-left: 8px;
      color: #BAC2D6;
    }
  }
  ::v-deep .van-picker-column__item {
    color: #002170;
  }
}
</style>